package com.ztools.wx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.card.CardMaster;
import com.ztools.common.model.pc.card.CardRechargeRecord;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.wx.service.WxCardService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: seeTools
 * @Date: 2023/6/26  18:14
 * @Version 1.0
 */
@RestController
@RequestMapping("/wx/card")
public class WxCardController {

    @Resource
    private WxCardService wxCardService;


    @RequestMapping("/getCardList/{memberId}")
    public Result getCardList(@PathVariable("memberId") Long memberId) {
        List<CardMaster> cardList = wxCardService.getCardList(memberId);
        return Result.success().data(cardList);
    }

    @RequestMapping("/openCard/{memberId}")
    public Result openCard(@PathVariable("memberId") Long memberId) {
        wxCardService.openCard(memberId);
        return Result.success("开卡成功");
    }

    @RequestMapping("/getCardInfoByNo/{cardNo}")
    public Result getCardInfoByNo(@PathVariable("cardNo") String cardNo) {
        CardMaster cardInfo = wxCardService.getCardInfoByNo(cardNo);
        if (cardInfo != null) {
            return Result.success("卡信息获取成功").data(cardInfo);
        }
        return Result.error("卡信息获取失败");
    }

    @RequestMapping("/getCardRechargeRecord")
    public Result getCardRechargeRecord(@RequestBody PageUtil<CardRechargeRecord> pageUtil) {
        Page<CardRechargeRecord> cardRechargeRecord = wxCardService.getCardRechargeRecord(pageUtil);
        return Result.success().data(cardRechargeRecord);
    }
}
